/**
 * @param {number[]} nums
 * @return {number[][]}
 */
var permute = function (nums) {
    const res = []
    const used = []
    const dfs = (path) => {
        if (path.length === nums.length) {
            res.push(path.slice())
            return
        }
        for (const num of nums) {
            console.log('num', num);
            if (used[num]) continue
            path.push(num)
            console.log('path', path);
            used[num] = true
            dfs(path)
            path.pop()
            console.log('path---', path);
            used[num] = false
        }
    }
    dfs([])
    return res
};

permute([1, 2, 3])